/*
 * Exception.h
 *
 *  Created on: May 14, 2011
 *      Author: xrose
 */

#ifndef EXCEPTION_H_
#define EXCEPTION_H_

namespace vLib{
class Exception : std::exception{
public:
	Exception(){}
	Exception(const string& s_error) throw() : error(s_error){
		if(error.size()>0){
			vlTrace("Thrown: %s\n", error.c_str());
		}
	}
	virtual const char* what() const throw() {
		return getError().c_str();
	}
	virtual ~Exception() throw() { }
	virtual const string& getError() const throw() {
		return error;
	}
protected:
	string error;
};

#ifdef _DEBUG

#define STANDARD_EXCEPTION(name) class name : public Exception { \
public:\
        name() throw() : Exception(#name) { } \
        name(const string& aError) throw() : Exception(#name ": " + aError) { } \
        virtual ~name() throw() { } \
}

#else // _DEBUG

#define STANDARD_EXCEPTION(name) class name : public Exception { \
public:\
        name() throw() : Exception() { } \
        name(const string& aError) throw() : Exception(aError) { } \
        virtual ~name() throw() { } \
}
};

#endif /* EXCEPTION_H_ */
